<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div id="box">
        <!-- v-指令传入的是变量，加''表示为字符串 -->
        <div v-hello=" 'red' ">11111111</div>
        <div v-hello=" 'blue' ">22222222</div>
        <div v-hello=" 'yellow' ">33333333</div>

        <div v-hello="mycolor">555555555</div>
    </div>

    <script type="text/javascript">
        //自定义指令
        /* 函数写法：表示创建和更新时都会调用执行el.style.background=binding.value */
        Vue.directive("hello", function(el, binding){
            el.style.background=binding.value
        } )
          



        var vm = new Vue({
            el:"#box",
            data: {
                mycolor:"red",
                // mycolor: "pink",
                // myname: "kerwin"
            }
        })
    </script>
</body>
</html>